package com.wuba.rxjavademo.tzx.create;

import com.wuba.rxjavademo.tzx.common.Base;

import java.util.ArrayList;
import java.util.List;

import rx.Observable;
import rx.Subscriber;
import rx.functions.Func1;

/**
 * Created by Tanzhenxing
 * Date: 2018/12/27 7:26 PM
 * Description:
 * Observable.empty():调用onCompleted
 * Observable.never():直接终止
 */
public class RxNever extends Base {
    public static void main(String[] args) {
        RxNever never = new RxNever();
        never.run();
    }

    @Override
    public void run() {
        Observable.just(1,2,3,4,5)
                .flatMap((Func1<Integer, Observable<Object>>) integer -> {
                    if (integer > 3) {
                        //return Observable.empty();
                        return Observable.never();
                    } else {
                        return Observable.just(integer);
                    }
                })
                .subscribe(new Subscriber<Object>() {

                    @Override
                    public void onCompleted() {
                        System.out.println("onCompleted");
                    }

                    @Override
                    public void onError(Throwable e) {
                        System.out.println("onError");
                    }

                    @Override
                    public void onNext(Object o) {
                        System.out.println("onNext");
                        System.out.println(Integer.valueOf(o.toString()));
                    }
                });
    }
}
